<style>
#shiftingAddPageContent dl span.error {
    position: absolute;
    left: 260px;
}
</style>
<div class="pageContent">
    <form class="pageForm required-validate">
        <div class="pageFormContent" id="shiftingAddPageContent">
            <input type="hidden" name="navTabId" value="${navTabId!''}"> <input type="hidden" name="id" value="${moveType.moveTypeCode}">
            <fieldset>
                <dl>
                    <dt>人员编号：</dt>
                    <dd>
                        <input name="personnelCode" size="22" type="text" maxlength="60" class="required" 
                        id="personnelLookup.personnelCode" labelFields="personnelCode,personnelName"
                        postField="personnelCode" suggestFields="personnelCode,personnelName,workCenterCode,workCenterText" 
                        suggestUrl="${rc.getContextPath()}/manage/personnel/personnelSuggest" 
                        remote="${rc.getContextPath()}/manage/personnel/validatePersonnel"
                        lookupGroup="personnelLookup"
                        warn="人员编号不存在！" />
                    </dd>
                </dl>
                <dl>
                    <dt>姓名：</dt>
                    <dd>
                        <input name="personnelName" id="personnelLookup.personnelName" readonly="readonly" size="22" type="text" maxlength="60" />
                        <input name="workcenterCode" id="personnelLookup.workCenterCode" type="hidden" />
                    </dd>
                </dl>
                <dl>
                    <dt>工作中心：</dt>
                    <dd>
                        <input name="workcenterText" id="personnelLookup.workCenterText" readonly="readonly" type="text" />
                    </dd>
                </dl>
                <!-- <dl>
                    <dt>人员类型：</dt>
                    <dd>
                        <select name="personnelTypeCode" class="required"></select>
                    </dd>
                </dl>
                <dl>
                    <dt>物料编号：</dt>
                    <dd>
                        <input size="22" type="text" maxlength="60" class="required" name="materialCode" type="text" postField="materialCode" 
                        id="materialLookup.materialCode"
                        suggestFields="materialCode,materialText" 
                        suggestUrl="${rc.getContextPath()}/manage/material/componentSuggest" 
                        remote="${rc.getContextPath()}/manage/material/validateMaterial" 
                        warn="<@label key='materialCodeNotExists.M'>物料不存在</@label>" lookupGroup="materialLookup" /> 
                        <input type="hidden" id="materialLookup.materialText" name="materialText" />
                    </dd>
                </dl> -->
                <dl>
                    <dt><@label key="shiftingWorkCenter.C,colon">实际工作中心</@label></dt>
                    <dd>
                        <select id="personnelLookup.workCenterCode" name="shiftingWorkcenterCode" class="required"> <#list permissions as permission>
                            <option value='${permission.workcenterCode}'>${permission.workcenterText}</option> </#list>
                        </select>
                    </dd>
                </dl>
                <dl>
                    <dt>日期：</dt>
                    <dd>
                        <input id="theDate" name="theDate" size="22" formate type="text" maxlength="60" class="required date" /> <a class="inputDateButton" href="javascript:;" />
                    </dd>
                </dl>
                <dl>
                    <dt>选择时段：</dt>
                    <dd>
                        <select id="periodSelect"></select>
                    </dd>
                </dl>
                <dl>
                    <dt>开始时间：</dt>
                    <dd>
                        <input name="startDateTime" size="22" formate type="text" dateFmt="yyyy-MM-dd HH:mm" dateGroup="dateTime" class="required date from" /> <a class="inputDateButton" href="javascript:;" />
                    </dd>
                </dl>
                <dl>
                    <dt>结束时间：</dt>
                    <dd>
                        <input name="endDateTime" size="22" formate type="text" dateFmt="yyyy-MM-dd HH:mm" dateGroup="dateTime" class="required date to" /> <a class="inputDateButton" href="javascript:;" />
                    </dd>
                </dl>
                <dl>
                    <dt>备注：</dt>
                    <dd>
                        <input name="memo" size="22" type="text" maxlength="60" />
                    </dd>
                </dl>
            </fieldset>
        </div>
        <div class="formBar">
            <ul>
                <li>
                    <div class="buttonActive">
                        <div class="buttonContent">
                            <button id="addShifting" type="button">添加</button>
                        </div>
                    </div>
                </li>
                <li>
                    <div class="buttonActiveGrey">
                        <div class="buttonContent">
                            <button type="button" class="close"><@label key="close.B">关闭</@label></button>
                        </div>
                    </div>
                </li>
            </ul>
        </div>
    </form>
    <div id="logGridForShiftingAdding"></div>
</div>
<ul id="closeBtn" style="float: right; margin: 10px 0px; display: none;">
    <li style="float: right;">
        <div class="buttonActive">
            <div class="buttonContent">
                <button type="button" class="close"><@label key="close.B">关闭</@label></button>
            </div>
        </div>
    </li>
</ul>
<span id="errorMsg" style="height: 30px; line-height: 30px; color: red; font-size: 13px; display: none;"></span>
<script type="text/javascript">
(function($){
    var $page = DWZ.context(), $parentGrid = $('#jGridForShifting', $page.data("_parent")), 
    $grid = $('#logGridForShiftingAdding', $page), $form = $('form:first', $page), $shiftingWorkcenter = $('[name=shiftingWorkcenterCode]', $form),
    dateFormat = 'yyyy-MM-dd', dateTimeFormat= 'yyyy-MM-dd HH:mm', today = new Date().formatDate(dateFormat), 
    perDay = 24 * 60 * 60 * 1000,
    common = ShiftingCommon();
    
    common.initPage($page);
    
    $grid.jGrid({
        base: '${rc.getContextPath()}/manage/shifting/',
        url: 'getShiftingList',
        height: 200,
        width: 950,
        autoLoad: false,
        columnresizeable: true,
        orderable: false,
        pageable: false,
        columns: [
            {field: '_index', text: '<@label key="serialNumber.C">序号</@label>', width: 40},
            {field: 'personnelCode', text: '人员编号', width: 100, orderTable: 's'},
            {field: 'personnelName', text: '姓名', width: 60},
            /* {field: 'personnelTypeText', text: '人员类型', width: 100}, */
            {field: 'workcenterText', text: '工作中心', width: 100},
            {field: 'shiftingWorkcenterText', text: '实际工作中心', width: 100},
            /* {field: 'materialText', text: '物料', width: 60}, */
            {field: 'theDate', type: 'date', format: dateFormat, text: '日期', width: 80},
            {field: 'startDateTime', type: 'date', format: dateTimeFormat, text: '开始时间', width: 120},
            {field: 'endDateTime', type: 'date', format: dateTimeFormat, text: '结束时间', width: 120},
            {field: 'memo', text: '备注', width: 60}
        ],
        gridbars: [
            {icon: 'delete', text: '清空日志列表', target: 'confirmTodo', action: function(){
                $grid.jGrid('clearData');
            }}
        ]
    });
    
    $('#addShifting', $page).on('click', function(){
        var $this = $(this), postData = {};
        if ($form && $form.valid()) {
            $.each($form.serializeArray(), function(){
                if (this.name == 'theDate' || this.name == 'startDateTime' || this.name == 'endDateTime') {
                    postData[this.name] = this.value.parseDate(dateTimeFormat);
                } else {
                    postData[this.name] = this.value;
                }
            });
            if (postData.startDateTime.getTime() >= postData.endDateTime.getTime() || postData.endDateTime.getTime() - postData.startDateTime.getTime() > perDay) {
                alertMsg.error('起止时间不合法！');
                $timeInput.addClass('error');
                return false;
            }
            //postData.personnelTypeText = $('>option:eq(' + $personnelType[0].selectedIndex + ')', $personnelType).text();
            postData.shiftingWorkcenterText = $('>option:eq(' + $shiftingWorkcenter[0].selectedIndex + ')', $shiftingWorkcenter).text();
            if (!common.validate(postData)) {
                DWZ.ajax({
                    url: '${rc.getContextPath()}/manage/shifting/saveShifting',
                    data: postData,
                    success: function(json) {
                        $parentGrid.jGrid('loadData');
                        $grid.jGrid('appendRow', json.data);
                    }
                });
            }
        }
    });
    /*
    $('[name=personnelCode]', $form).on('change', function(){
        var personnelCode = this.value;
        if (personnelCode) {
            $.ajax({
                url: '${rc.getContextPath()}/manage/shifting/getPTAsByPersonnel',
                type: 'POST',
                data: {
                    personnelCode: personnelCode,
                },
                dataType: 'json',
                success: function(ptas) {
                    if (ptas.length) {
                        $personnelType.empty();
                        $.each(ptas, function(index, pta){
                            $('<option/>').attr({
                                value: pta.personnelTypeCode,
                                selected: pta.defaultTypeFlag == 1
                            }).text(pta.typeText).appendTo($personnelType);
                        });
                    } else {
                        $personnelType.empty()[0].selectedIndex = -1;
                    }
                },
                error: DWZ.ajaxError
            });
        } else {
            $personnelType.empty()[0].selectedIndex = -1;
        }
    });*/
})(jQuery);
</script>